import { Component } from "react"
import axios from "axios"

//7.页面组件导入store
import store from "./store/storeIndex"
export default class Page1 extends Component {
    componentDidMount() {
        axios.get('http://121.89.205.189:3000/api/pro/list').then(res => {
            console.log(res.data.data);
            store.dispatch({ type: "getProList", payload: res.data.data })
        })

    }
    render() {
        // console.log(store.getState().count);
        // const count = store.getState().count
        const proList = store.getState().pro.proList
        return <>
            <h1>Page1-------{store.getState().count.count}</h1>


            <button onClick={() => {
                //修改全局数据
                //触发add
                store.dispatch({ type: "add1" })
            }}>点击加1</button>

            <button onClick={() => {
                //修改全局数据
                //触发add
                store.dispatch({ type: "addNum", payload: 5 })
            }}>点击加指定数</button>

            <ul>
                {proList.map((item) => {
                    return <li key={item.proid}>{item.proname}</li>
                })}
            </ul>
        </>
    }
}